﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Util.ImageProcess;
using System.IO;

namespace YLClient.Util
{
    public class ImageProcessHelper
    {
        /// <summary>
        /// 压缩图片以供发送 
        /// </summary>
        /// <param name="filePaths"></param>
        /// <returns></returns>
        public string CompressImages(string[] filePaths)
        {
            var tempdir = System.Environment.GetEnvironmentVariable("TEMP") + "\\YLTEMP";
            if (Directory.Exists(tempdir) == false)
                Directory.CreateDirectory(tempdir);
            var exisitFiles = Common.getDirFiles(tempdir);
            Directory.CreateDirectory(tempdir);

            filePaths
                .Where(f => exisitFiles.Contains(f) == false) //已经存在的文件不重新压缩
               .AsParallel()
               .ForAll(filePath =>
               {
                   var saveFilePath = tempdir + "\\" + Common.getFileName(filePath);
                   ImageProcess.DefaultCompressBitmap(filePath, saveFilePath);
               });

            return tempdir;
        }
    }
}
